Added time formatting. Lots of refactoring.