Finalized code for programming assignment 2