Mid-cleaning up...

Organizing stuff into functions, commenting, etc.

Next: More cleaning, testing, integrating!