refactor model package and implement most of the database operations