Refactored for visibility and better documentation