Adding code from lab9 problems