Ugly, but working problem 6