Added null check in getNumberOfMatches