add condition variable, and passing pointer to struct rather than making
multiple copies