Factor out some repetitive code in rethink adapter, fix code that
was breaking tests, fix some code that was causing panics with derefs