massive cleanups, mostly around templates