Thistlethwaite's solution code added