test fixes and refactorings