Function definitions for assignment 2.