Refactoring some code and adding a logger.