Fix issue https://github.com/Macaulay2/M2/issues/164, add test for it