Adding code from lecture and homework3 skeleton