Redid it with pointers and no global variables.