added context validation switch, initialised null containers to get around mongodb npe bug, and other minor refactorings