Modified getFirstWord method