fixed sleeping and retrying logic.