handle direction changes while sorting