More test and code refactoring