refactored column sort code