Refactor to improve comprehensibility