Refactoring collection.js