minor changes in the code and added some comments