Rewrite parts to leverage improved database API