templates and some fixes