Added a lot of parameter controls, so now errors with user-friendly text are reported when something goes wrong.