Moved background clean up inside the lock