put this in a separate function

code cleanup