changes to the code and some comments added