Commented problem 3 approach, optimized a bit