Updated code after lecture 2