wrote assignment2 functions