added a clock and fixed bugs