Lots of code cleanup.