refactoring of data to templates, and working with database