Optimized 4th solution