Cleanup and leak prevention