Updated code for the assignment