Ok. This is all convoluted. Need to simplify because there's bound to be race conditions.