working for the second part of assignment 3