Simplify queries, prevent crash if connection lost