Implemented problem 6