Solved Problem 109 (not pretty...)