Added index substitutions and type_r