fix tests, remove duplicate code