Final changes, added javadoc and logging.