fix #1448, fix #1566, work on #1585