Added some error-checking