Added functional code to problem 2