Updated with comments. Moved couple of log messages around.