improved logging with comments, and other minor fixes