Refactored hit test