Logging and cleanups

Add and configure log4j instead of the System.* prints and clean up the
code a bit.