change forEach to for loop to use break
added reset function