Implemented second task from exam 2.