wrote functions for assignment 2