Added some error check