moving hit_matrix logic to a subfunction.