It is tested 'as-is'.

Why is there 2 clean up functions? one at the and of 'main' and another at the end of the action?

And they both have exactly the same instructions.