is there a sane way to refactor this such that these two clauses can be combined instead of duplicated?