Added boundary condition check.