Basically finished

Need to test: expect a lot of errors.
merged with cleaning up