Added loop and conditional to generate tmp check