Refactor these repeated lines into a "check..." function?