fixing bugs with models and db functions