Fixed a lot of issues, just need to pass integration tests.