fix #37666
fix #37456
fix #22904
fix #37651
addition to fix #37651: complete layout calculations