Fixed many bugs in tests.
I believe this fixes termination problems of EM.