wrote requested code and comments