Function applyUserSpecifiedConstraints done (needs performance improvement at all levels since it has 600 lines of code)