Updated to include some checking for error wrapping.