refactor comprehension out into function