use new IO API
improve error handling