Refactor to support flexible data model