Made error handling as separate function. Added returning result as JSONP