Cleanup helpers, with units tests