Refactored the code into multiple classes.