added check for NULL ptrs in init and io