added debug() in sort function