Refactored the code a little bit and could use a little more tweaking for logic but I think it has the proper output just makes a couple extra steps.