fix a bunch of race conditions with the modal

Signed-off-by: Joshua Rubin <jrubin@zvelo.com>