test fixes, refactoring