Added checking for error status - Added maxtries so that the script won't wait forever if there is something wrong