Fix add establishment bug and move some more code out of agreementsvm.