correct sql bugs