Major refactoring separating MySQL from SQL database