Created the fuction as per instructions