fixed most of query issues