template cleanup and establishment cleanup