Fix bug that made some tests fail randomly