Simplified code to be without setIntervals