Cleaned up code, made it handle unknown errors too
If there are no parameters, make sure the parameter array is empty instead of a containing a single zero-length string