semi sorting
not good, big refactor ahead