Minor code cleanup, sort while locked