final code for assignment 2