homework lecture 3 both done, cleaned up code