sorting before return