fixed terrain index out of bounds bug