Done restructuring. Lots of bugs left, though.