Fixed bug in reset function