Added logic for rotation of words