fixed several bugs and tests. Test suite almost running to the end. Race conditions are causing problems