adds self-invoking query function