Some cleanup and comments added.