Solved problem 105, optimized problem 104