This looks extremely similar to below. Any way to either call that function here or have them both call a utility function?