Refactored according to solutions