added templating facility, bugfixes