Small changes to SQL code