Massive refactor for tests