further spruced up the sort logic, and setup default sort state