Functions for programming assignment 2