Refactored for modularization, incorporated config usage.