Improve constraining of sum constraint.
Add internal documentation.