refactor templates and implement backend templates