Refactoring. Simplified logic