refactor code in model.py

Plus, add stubs for ObjectTypes and Collections,
and improve tests for generators.