code updated and comments added