made some major changes related to tracing and fixed some bugs along the way.