Most parts of this patch come from wendelin, plus the tests and some fix.
Attach a file by drag & drop or click to upload