Added debug tracing, cleaned up some comments