Add: safe query function
fixed some stuff