refactoring and fix of mean