Fixes SQL issues