Some fixes. Seems I started some refactoring few years agon, and didn't
finished it.