Rewrites in gorethink (rethinkdb) and passes all tests