Restructure into modules

Here's the grand restructure experiment part #1.

From here I'd recommend creating each of the 3 modules, changing the internal code slowly... and profit.