working version of the template parser