Reimplemented the db access functions in a separate script.
Small changes in model