adding error checking and API responses