I think the code is not really readable dure to initialisation block.
You should extract this code outside the function object.