Refdb2: refdb + merge conflicts resolved

Most of this is from the original refdb