Two way sorting problem