Fix bugs in constraint handling mechanism.