refactored option parsing