improved error check: inRange()