Fixed MIMA

Just applying the fixes that I did on the 2.2.x branch to master, so
when we fork 2.3.x, it will be easy to enable MIMA.