Consolidated method for problem 18.