Refactoring, optimization