Perhaps break this out into a util so it's reuseable (even though we may not use it in that way)?