fixed bugs around sort/limit not specified. added a test.