Changed range_mat to shape_mat on line 163