Moved count reset into a dedicated function so it can be called by end