Functions for assignment 2