fix db queries