FIXME: It's not pretty, but this fixes a race condition somewhere :x