Added some null checks to fix a bug where no text is recognized.