Smart matching and code motion