Changed the releation of templates

And some other fixes.