Reduction and irreducibility for words and tree-words