Solution to 11. A bit messy for such code, though.