Code for lecture 18.