yabadabadoo
At last it works for now, though code is ugly, not tested and obviously stupid.