fixing sorting error