Understanding structural and electrochemical stability in high energy density layered oxide cathodes for Li and Na ion batteries