Fix errors on startup
Rework SQL to use PreparedStatements