Final cleanups.

To be honest, I think this is bug free. This is ready to get merged into master branch.