Fix the db queries