added support for collections

in the process, improved documentation and refactored internals