Fixed bug in time sorting