fixing condition to check process finish