Problem 6 implemented