Cleanup of template structures