refactored data model and fixed all functions