Updated hit test  function