refactor constraint handling