fix to applyConstraints algorithm