Fixed search assumption in sort. Still need to fix some bugs.