Revert "Revert "Update MAP code from upstream.""

This reverts commit 9ae8d2378449f0b69599fecdef740d06d80e96be.