Refactor big method, formatting/whitespace