Working AM analysis + various bug fixes.