Code refactoring. No major logic changes