Added timer, refactored some code