Refactoring the data model

Moving the model logic into the CP