Revert "Revert "refactoring""

This reverts commit 80b11c9d060113c630b0a5cfd346c6072ad63451.