added code from lecture 3_1