Refactored code to fit a modular design pattern.