R stuff and db reformatting