make tests work, some rafactoring