Fixing algorithm. Constraints made it impossible