implement ML2 changes from alexei lugovoi