cleanup function concurrency bug solved