add functionality for collections, refactor code, and add test