General refactoring for reuse.