see lecture 9 attached