fixed bug that was causing incorrect sorting