finished refactoring em: tested, identical to old