refactoring and tuning