refactored the updating constraints code.