refactored and fixed some races