I send this patch to receive your comments, and this one shouldn't be accepted (e.g. tests are not modified). It can be seen 'live' at http://hg.aplavin.ru (the server runs exactly this version of code).