Revert "Revert "Refactor""

This reverts commit 6fa478237f738b48ef8d30f2622540b76a36a888.