Attempted fix for sort bug