restructured the js logic, added the timer