Fix some bugs about teacher sorting