Write remaining functions for problem 2