filthy wip
fix sorting
cleanup and refactor