moved element handling code for EM engine to separate functions