Slightly refactor logic