refactored some option-handling code