Some improvements and bugfix in templates