Finished functions for part b. Untested.