Final code for assignmen4