finished adapting the tutorial code