Fix bug in reset function