Added in some error checking