fix sorting helper