some speedups
fix racecondition
change tests