added directed cyclic graph to store words