Refactoring of #952