Added extended error checking