Fix bug where sort levels would close premature

rebase