Fixed some bugs and added a template parser.