Fixed major bug in template compiler