Added some error checking to queries and worked around a super rare client crash