Refactored relations.js