Fix some bugs in MAP calculator revealed after testing, to be continued...