Fixed invalid SQL in some circumstances
Last comments respect safety choice