add `cleanup_guard` plus unit tests