assorted fixes per comments from @pozdnyakov and @rafal-krypa