moved sorting procs to controller