Refactored ugly method