Adapting tutorial code