refactored to allow sorting of columns