fixes a race condition (closes #26, closes #27)