fixed query adding algo.