Adding return codes for constrain, plus tests.