Modified Sort and Code Cleanup