[TASK] Refactor code and refine tests

Builds on https://github.com/FluidTYPO3/flux/pull/325 which is still WIP and under discussion. Do not merge yet!