added logging code, disabled for dead code elimination; fixed a number of bugs; stabilized tests