refactoring and add remote io error check.