Moved drawing into function and added time counting