added comments and some code refactoring
code additions for assignment 5