Added options, defaults and some refactoring