copy from branch 4.0