Fixed the code issues found in integration, rewrote the tests to match the changes.