Error fixes and general code cleanup.