Adding the final tweaks and fixes

Now all tests (both unit and functional) are running successfully.

Only thing to add now is a few tests that show the reason of the
refactor.

And of course a migration flow for the state file. Will try to do that
before the end of the week, so this PR can be merged together with that
coming PR.