second part of the question implemented