Rewrite container cleanup
Rewrite in python should be more correct