Add error checking, since this seems to fail on some mobile devices