Worked on it a bit. I moved it into another function. It's still quite long, though. Reason are the long error texts...