Add bug fixes to agreements and some code cleanup.