Modularize Sorting Code