implement option parse and tiny refactoring