renamce doc_words to doc_queue and cleaned up code