Fix SQL and create basic model code