Refactored everything for readability.