Refactored code into multiple methods.