maybe factor this out into a function?