Adding code from examples 6 & 7