Refactor ugly tutorial code