implemented the clock, fixed some bugs