doing sorting manually now instead of using php sort methods