bugfixes and much improvements in the template