Fix bugs in template rendereing and other compile failures