imported the rest of the tutorial code, sort of cleaned up