sort by gender function