Started refactoring, but have to fix some test