refactor option parsing