ORDER BY plus one typo

Added some ordering functionality, see inline comments.