Rewrites in rethinkdb. Updates tests and passes.