Refactored P2 recursive for solution