Fixing code style to match original code
Handling related fields in schema
Factory for creating collections