move query to model