Fixed dumb error in cleanup code, and updated inline comments