updated lecture6.R