Hmm, this looks suspiciously like something that should be factored out into a function.