apply fixes from #36 since they never made it into master branch