Fixed the isInRange function