Fix template parser and builder

Closes #210