refactor database structure