repaired and refactored handling of collections