refs: add "for_each_ref_in" function to refactor "for_each_*_ref" functions