can't figure out how to stop race condition