Extracted js functions and added a timer