Rest of code from lecture