Fixed the old template deletion and edge deletion logic.