Modify 'same_shape' function