Code for problem#12 refactored.
Refactored code for problem#26.