Added better error handling, for json & http