Fixing cleanup code