Moved select order by field into its own function for smoother code.