rewriting with template system