Fixed a race condition

Closes #2.