move query to a function