Fixed sort order bug and added name mode parameter