Teaks and refactoring of existing functionality, added better handling of parameters for CLI. Unit test coverage also.