code for lec 6. Not compilable, due to undefined variables.