em implementation, but with bugs