Wip mirroring code, refactor couchbase functions to module