Creating query and add functionality