modified the function for assignment2