backport goodies from pomf