Small logic refactoring