Improve test cleanup code