Added Problem 8 functionality