Add optional cleanup function for tests