implemented functions for assignment 2