Fix sort problems