added sort API, removed debug code.