Work on constraint, do some refactoring