fixed code to be more logical, fixed a couple bugs, and made retries a input variable