Fixes for SQL