Fix race conditions, looks like dirty hack (