refactor, finally fix tests