Minor improvements and some code cleanup.