Fixed a bunch of bugs in template installation