code after addressing all comments