Fix bug that could occur on units out of range

Fix bug that could occur on units out of range