added javadoc comments, tidied up logging a bit