fixes #117
fixing some race conditions, and adding test checks
update tests