Added support for custom collections and fixed some other bugs