Add log4j and some refactoring.