Refactored to clean up code and make next steps easier to implement.