Introduced logger and some refactoring