Changed square-setting algorithm