attempt at fixing a possible race condition