Refactor machine into sets of interfaces

Rewrite a ton of the code to be cleaner and simplify the abstractions in the machine.