most of the backend model code