Fix #316 (problem was race condition)