Improve templates to use inheritance