Implemented problem 4