added fix for cleanup when remove-item is mocked

When remove-item is mocked the cleanup function doesn't work.
I've added a test to prove that and fixed it.