Refactoring and adding log4j functionality (not yet fully implemented).