Refactor getHeightAt to getZ, add error checking