Misc fix ported from Plack