JS implementation of evermd in a more canonical way