Extended and fixed template engine
some more changes