improve substitute pattern