corrected construction of the boundaries mask