simplify the code by using array_map and join

The testsuite still passes after my changes and the code gets much
easier. Personally, I wouldn’t even put these functions into a module in
the first place, but YMMV :).
Merge pull request #1 from mstap/master

simplify the code by using array_map and join