Added some error catching