Added functionality from chapters 12 and 13