Replace closure with custom cleanup