I've tested the patch once more and found that it contains a small error. Here is a fixed one.