generalized and more efficient cat implementation
Merge pull request #7600 from Jutho/jh/cat

generalised and improved cat implementation