Updated so that it's basically 100% equivalent to Mongo
Minor fixups