refactor em algorithm and write test