refactored some  sorting into orddict