Issues # 806, #812, #813 and various fixes