Fix boundary condition checking bug.