Changing the model structure

and little bug fixes