Some refactoring to allow mock the server
Fixed test suite exception.
Some tests are still breaking.