first version
fix exceeded callstack on queries and random id out of bounds