Merged maps code from 4.0-stable