Implements all constrains, solves efficiency issue