Do we need to be doing a typeof check on cleanup for every iteration of the loop? What would cleanup be if not a function? It looks like `if (cleanup) { cleanup(); }` would suffice.