Lots of cleanups based on pyflakes.
More cleanup of unused functions / variables.