Solution 11. This one was ugly.