Ported BS beta code over from diverged branch.