major refactoring and supporting custom options