Added checks on I/O erros and so