starting to build sort functionality. refactored some js