adding code from lecture