Code fixes

Hi Pablo,

here we go, my pull request with the code fixes.
I have added unit tests for the idToMongo() stuff and for sure ran all unit test to see if nothing else breaks.

Cheers, Anton