implemented #55, plus other fixes