Fixes #777 Dispose of the previous template before adding the same one again.