Revert "huge refactoring"

This reverts commit e3cf5ea79788e9c783bcebc3dab12213389bd41c.