Implement functions for assignment 2