Added timed updates and reorganized the code