Add sanity check and extra debug message