Untangle type & code dependencies

Currently, the submodules depend on each other in cyclic manner. That is a bit ugly and confusing, so try to move the types somehow around to untangle it.

Besides making the code nicer and easier to understand, this would also be a dependency for splitting the project into sub-crates (if we ever wanted that).