Electron correlation in doubly excited states of helium and extensions to beryllium and magnesium