Move mongo hooks to tally.py, much more sensible place. Tidy up a bit.