Started work on mergeWords function. It's a little buggy and maybe inefficient but I can refine it later.