Can you combine these two functions into one that's slightly more generic?