Updated some error handling