Refactored collection API and created some tests