basic working version
Simplified by adding token template replacement