Refactor to avoid duplicate check