add sanity check and tracing