Various fixes of #801