Can you pull this out into a couple of helper functions?