refactory query view