Revert "Revert "big rewrite 4""

This reverts commit 232b4b7814b7d2fd7d0870c5251d24167d95f06e.