Adding order by and removing some redundant functions