add portability fixes from #1720