Various bug fixes for dbo rewrite