Fix the out-of-boundary issue