adding code from 3nd lecture