Added json error handling and cors support.