Given final touch  by adding comments and correcting some minor mistakes