refactoring + improve options handling