Refactored for a modular approach. Plus clean ups.