code for lecture 2