added implementation based on collections
added implementation based on collections