refactored, and added in templates