refactored ordered_set solution