code functional except for concatenation of output part