Fix test cases occasionally failing (possible race condition)

Fixes #8