Massive refactor to break things into functions and better flow and readability.
Rewrote beginnign section to make intent much more clear.