Added comments, fixed a couple of errors and refactored some of the log messages.