Rewriting with kyrie

It could be done with something similar to this example. Please notice the huge amount of replicated code that should be factorized. I didn't do that because I'm uncertain about the possible side effects.