Maybe factor this out to a util func instead of repeating the code?