Updated function in Problem 2