Cleaner code for time formatting
Fix an issue that would sometimes cause an infinite loop