Fixed infinite loop when trying to access beyond map boundaries