I agree with @georgebrock. I think this patch isn't cool code, but I can't find better way(with minimal patch) than this PR.