fix crash, add debug mode on/off