added functions to streamline range check and calculate height of terrain