fix options handling and refactor