Updated sql loading and formatting, refactored code