merged fixes by @snorfalorpagus