Removed dup code

Moved the time sorting code into a function, fixing some copy pasta.