Refactored for clarity. Also created a config module.