Removed code duplication in templates