Added more protection for SQL problems