Improvements to SQL in main class