Backported several patches from version 0.8 to fix this. Signed-off-by: Rosen Penev <rosenp@gmail.com>