Sort on time field
Correctly sort and DRY up SELECT query
Correctly select count of states