A few bug fixes and improvements for SORT BY