refactored option selection code