refactored the templates to factories