why do these need to be globals? - make them statics local to the function?