restructuring the model and many other fixes