wip - it is all a mess, but somehow it works