Kind refactor

@Zizaco can you take a look and test please.

No functional changes for now, but this will allow us to extend things a lot better.