bugfix: fix race condition