Added some missing error handling