refactoring & optimize