updated the code and comments