ugly workaround for issue #1833, but doesn't leak memory and isn't a security hole, unlike my previous attempt :S