Fixes for running SQL queries