Code cleanup and restructuring. Still learning...
Tests!