Improved error handling

JSON parse errors are now caught, and missing parameters to the method raise an error.