finished implementation of untested EM