My solution to the task with some style fixes