ported some changes from tracing which fixed latent bugs.