patch from loopj branch