Added nested sort integration test
Fixed some bugs