Code cleanup and comments. Not proud about the pyflakes warning disable hack.