Refactoring, logic update