Some refactoring, given comments on #144