Revert 8137f8a..279f85a

This rolls back to commit 8137f8aefb0da6c3e76371f2049ac84f6eb86a50.
big refactor