Working with templates, some refactor