implemented first part of homework
implemented second part of homework