fix orderby

fixes orderby and adds more tests for it