Added constraints in code and refactored a bit