Use mixin instead of whole code

Rebase of #11512, leaving variables as-is.