fixed a bug which could cause template be added more than once