Constraint generation + bugfixes