save query and some bug fix