Refactoring. Full code review