Refactor queryDB