analysis refactoring and tests