Simplify template, use inheritance.
(cherry picked from commit 96e78ad)