sort was not working for even number of elements fixed that