Some bugfixes for amm and lm