Optimization&refactoring