Implemented key-collection more efficiently, not doing it if not necessary.