Most of the logic for sorting based on store is worked out