code from lecture 3