Refactor to avoid some repetition