updated error handling and json output