Check if query is not null
fix bug