Fix bugs in sort/sort_test + sort kernels using key/compare macros