Working functions for ProgrammingAssignment2