Strengthen cleanup code. Fix build.