Altered the script so it does not disconnects when an error occurs