refactoring and tests re-enabled