Code for assignment 2