code presented in the Youtube tutorials by TwistedEquations