Refactor for easier comprehensibility