Fix bug 3166 and clean up solution code.