New data for the total cross section
$\sigma(e^+e^-\to\mbox{hadrons})$ in the charm and bottom threshold
region are combined with an improved theoretical analysis, which
includes recent four-loop calculations, to determine the
short distance $\overline{\rm MS}$ charm and bottom quark masses. A detailed
discussion of the theoretical and experimental uncertainties is
presented. The final result for the $\overline{\rm MS}$-masses,
$m_c(3~\mbox{GeV})=0.986(13)$~GeV
and
$m_b(10~\mbox{GeV})=3.609(25)$~GeV,
can be translated into
$m_c(m_c)=1.286(13)$~GeV
and
$m_b(m_b)=4.164(25)$~GeV.
This analysis is consistent with but significantly more precise than a similar
previous study.