Adding code from Lecture 9