Fix the boundary calculating bug.