finished functions for chapter 3