Added in some error checking code.