cleaned up the code a bit
added logger instead of System.err.print()