Fixed retrieval issues with ORDER BY

The program would error after the sorting code was placed. This fixed
that issue.