fix bugs on db quuery