refactored based on full EM derivation