wrote general addWord function