small refactor + race condition hack
refactor
bugfix