Some bugfixes; merged collection and document handling