Refactored to smaller methods