Added some error checking, but it needs to be shown to the user