Add some unit tests and include analyzer for key fields too.
Improve detection of collection fields

Partially addresses #58