Cleanup and refactor

Added constants, refactored some calls. Now works writing relations
between Content and Media as expected.