patched up the model and sql statements