Solves problem 46
Solves problem 40