Wrote answer
Refactored