Refactor solution 2