reimplemented template engine