Apply some bugfixes to template