Moved collection logic to the collection

// And added some comments.