Tests cleanup

Tests will need a larger refactoring, especially separating integration and unit tests, but the most urgent need is to make them pass.