Optimised the constrain function
Merge pull request #2 from sambeckham/feature/optimisation

Optimised the constrain function