safemalloc in sort added