Fixed sorting weirdness

Sort of. Still need to revisit, but this works for now.