code refactoring to ease modifications and passing optional parameters