This function is so similar to the one below. Can you just have a single one?