DB Rewrite

Accidentally merged an old branch of db_rewrite. This is the correct merge!