Added some error handling