Final code for Assignment 2