Fixed an off-by-one leading to a crash at map boundaries