Changed some of the control flow logic to reduce the amount of code and streamline the solution.