Several small plugin enhancements

Proposing several small updates in the plugin related to code and error handling.

I have one more problem that I'm investigating with handling database errors but I'll follow up with a patch if I could intercept it properly.