Fixed polling error, add error check during polling, added write function.