Fixes race condition

I ran into something similar to #159, hopefully this will take care of that