Fixing MAP implementation