Refactor long method to smaller methods