Backported modal featurs from 3.5 branch.