improved reset function