Minor logic change and better tracing