Clean up code and bug fixes for agreements.